home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
w3dvb5
/
lineanas.bas
< prev
next >
Wrap
BASIC Source File
|
1997-12-22
|
31KB
|
1,224 lines
Attribute VB_Name = "Lineanas"
' Modulo per l'eliminazione delle linee nascoste.
'
' ATTENZIONE - La Sub LineNas Φ la routine principale
' di questo modulo e (sigh!) non funziona.
' Comunque altre routine e variabili presenti
' sono indispensabili per l'algoritmo del pittore
' che Φ funzionante. Ergo, non eliminate il modulo
' dal progetto! Non funzionerα pi∙ niente!
Public AlgoritmoAttivo As Integer ' 0 - Pittore, 1 - Linenas (serve per Orienta)
Public Const Nscreen = 10 ' // Ci saranno Nscreen x Nscreen quadrati
Public density As Double
Public d As Double
Public c1 As Double
Public c2 As Double
Public xfactor As Double
Public yfactor As Double
Public Xrange As Double
Public Yrange As Double
Public Xvp_range As Double
Public Yvp_range As Double
Public xmin As Double
Public xmax As Double
Public ymin As Double
Public ymax As Double
Public zmin As Double
Public zmax As Double
Public deltax As Double
Public deltay As Double
Public denom As Double
'Public zemin As Double
'Public zemax As Double
Public eps1 As Double
Public trset() As Integer
Public dummy As Integer
Public vertexcount As Integer
Public x_center As Double
Public y_center As Double
Public r_max As Double
Public x_max As Double
Public y_max As Double
Public x_min As Double
Public y_min As Double
Type Vertexes
Vt As Vec_Int
Z As Double
Connect(5) As Integer
End Type
Public VV() As Vertexes
Public pVertex As Integer
Type Nodo
idx As Integer
jtr As Integer
nextn As Integer
End Type
Public VScreen(Nscreen, Nscreen) As Nodo
Type Point
Pntscr As Vec_Int
zPnt As Double
nrPnt As Integer
End Type
Type linked_stack
p As Point
q As Point
k0 As Integer
nextn As Integer
End Type
Public stptr(1) As linked_stack
Sub add_linesegment(Pr As Integer, Qr As Integer)
Dim iaux As Integer
Dim p As Integer
Dim i As Integer
Dim n As Integer
Dim Pt(3) As Integer
Dim p_old(3) As Integer
Dim Pnr As Integer
Dim Qnr As Integer
Pnr = Pr
Qnr = Qr
If (Pnr > Qnr) Then
iaux = Pnr
Pnr = Qnr
Qnr = iaux
End If
' Ora: Pnr < Qnr
p = VV(Pnr).Connect(0)
If (p = 0) Then
VV(Pnr).Connect(0) = 1
VV(Pnr).Connect(1) = Qnr
Exit Sub
End If
n = VV(Pnr).Connect(0)
For i = 1 To n
If VV(Pnr).Connect(i) = Qnr Then Exit Sub ' Giα nella lista
Next i
n = n + 1 ' Ora Q deve essere posto in p[n]
If (n Mod 3 = 0) Then
p_old(0) = VV(Pnr).Connect(0)
p_old(1) = VV(Pnr).Connect(1)
p_old(2) = VV(Pnr).Connect(2)
' Blocchi di tre interi
For i = 1 To n - 1
VV(Pnr).Connect(i) = p_old(i)
Next
VV(Pnr).Connect(0) = n
VV(Pnr).Connect(n) = Qnr ' // n Φ un multiplo di 3
' // *p=n, p[1],..., p[n] usati
' // (p[n+1], p[n+2] liberi)
Else
VV(Pnr).Connect(0) = n
VV(Pnr).Connect(n) = Qnr ' // n non Φ un multiplo di 3 (e n > 1)
End If
End Sub
Function ColNr(x As Integer) As Integer
ColNr = (CLng(x) * Nscreen) / LARGE1
End Function
Sub dealwithlinkedstack()
Dim Pt As linked_stack
Dim p As Point
Dim q As Point
Dim k0 As Integer
Dim Ptr As Integer
Ptr = 1
Do While Ptr <> 0
Pt = stptr(Ptr)
p = Pt.p
q = Pt.q
k0 = Pt.k0
Ptr = Pt.nextn
linesegment Form1.Pict, p, q, k0
Loop
End Sub
Sub LineNas(Pic As PictureBox)
Dim i As Integer
Dim Pnr As Integer
Dim Qnr As Integer
Dim ii As Integer
Dim vertexnr As Integer
Dim Ptr As Integer
Dim iconnect As Integer
Dim code As Integer
Dim ntr As Integer
Dim i_i As Integer
Dim j_j As Integer
Dim jtop As Integer
Dim jbot As Integer
Dim jI As Integer
Dim trnr As Integer
Dim jtr As Integer
Dim Poly() As Integer
Dim nPoly As Integer
Dim iLeft As Integer
Dim iRight As Integer
Dim nvertex As Integer
Dim ntrset As Integer
Dim maxntrset As Integer
Dim VLOWER(Nscreen) As Integer
Dim VUPPER(Nscreen) As Integer
Dim Orient As Integer
Dim maxnpoly As Integer
Dim totntria As Integer
Dim testtria(3) As Integer
Dim xsmin As Double
Dim xsmax As Double
Dim ysmin As Double
Dim ysmax As Double
Dim nrs_tr() As Trianrs
Dim deltax As Long
Dim deltay As Long
Dim rho As Double
Dim Theta As Double
Dim Phi As Double
Dim x As Double
Dim Y As Double
Dim Z As Double
Dim xe As Double
Dim ye As Double
Dim ze As Double
Dim xx As Double
Dim yy As Double
Dim fx As Double
Dim fy As Double
Dim Xcenter As Double
Dim Ycenter As Double
Dim Ps As Vec_Int
Dim Qs As Vec_Int
Dim vLeft As Vec_Int
Dim vRight As Vec_Int
Dim p As Vec3
Dim pNode As Integer
minvertex = 32000
maxntrset = 400
AlgoritmoAttivo = 1 ' Per Funct. Orienta
Erase stptr
nvertex = MaxVertNr + 1
ReDim Vt(nvertex)
SetVista rho, Theta, Phi
SetLimitiVista xsmin, xsmax, ysmin, ysmax, nvertex, Vt()
' Da InitGr
x_max = 10
density = X__max / (x_max - x_min)
y_max = y_min + Y__max / density
x_center = 0.5 * (x_min + x_max)
y_center = 0.5 * (y_min + y_max)
zfactor = LARGE / (zemax - zemin)
eps1 = 0.001 * (zemax - zemin)
' // Calcola le costanti del video:
Xrange = xsmax - xsmin
Yrange = ysmax - ysmin
Xvp_range = x_max - x_min
Yvp_range = y_max - y_min
fx = Xvp_range / Xrange
fy = Yvp_range / Yrange
If fx < fy Then
d = 0.95 * fx
Else
d = 0.95 * fy
End If
Xcenter = 0.5 * (xsmin + xsmax)
Ycenter = 0.5 * (ysmin + ysmax)
c1 = x_center - d * Xcenter
c2 = y_center - d * Ycenter
deltax = Xrange / Nscreen
deltay = Yrange / Nscreen
xfactor = LARGE / Xrange
yfactor = LARGE / Yrange
ReDim VV(nvertex)
' Inizializza l'array dei vertici:
For i = 0 To nvertex
If Vt(i).Z < -100000# Then
Erase VV(i).Connect
Else
Erase VV(i).Connect
VV(i).Vt.x = xIntScr(Vt(i).x / Vt(i).Z, xsmin)
VV(i).Vt.Y = yIntScr(Vt(i).Y / Vt(i).Z, ysmin)
VV(i).Z = Vt(i).Z
' MsgBox "x= " & VV(i).Vt.X & "y= " & VV(i).Vt.Y & "z= " & VV(i).Z
End If
Next i
Erase Vt
' Trova il numero massimo di vertici in un solo poligono
' e il numero totale dei triangoli che non sono
' retrosuperfici:
maxnpoly = 0
totntria = 0
nPoly = 0
For k = 1 To UBound(FileVertex)
nPoly = 0
i = Abs(FileVertex(k).Vert(1))
If i > 0 Then
For j = 1 To FileVertex(k).Count
i = Abs(FileVertex(k).Vert(j))
If i >= nvertex Then
MsgBox "Vertice nr." & CStr(i) & " indefinito"
End
End If
If nPoly < 3 Then testtria(nPoly) = i
nPoly = nPoly + 1
Next j
If (nPoly > maxnpoly) Then maxnpoly = nPoly
If Not (nPoly < 3) Then ' // Ignora il segmento 'libero'
If (orienta(testtria(0), testtria(1), testtria(2)) >= 0) Then totntria = totntria + nPoly - 2
End If
End If
Next k
' =========
ReDim Triangles(totntria)
ReDim Poly(maxnpoly)
ReDim nrs_tr(maxnpoly - 2)
' // Lettura delle facce dell'oggetto e memorizzazione dei
' // triangoli:
For k = 1 To UBound(FileVertex)
nPoly = 0
For j = 1 To FileVertex(k).Count
i = Abs(FileVertex(k).Vert(j))
If nPoly = maxnpoly Then
MsgBox "Errore di programmazione maxnpoly"
End
End If
Poly(nPoly) = i
nPoly = nPoly + 1
Next j
' If (nPoly = 1) Then
' MsgBox "Solo un vertice del poligono?"
' End
' End If
If nPoly = 2 Then
Call add_linesegment(Poly(0), Poly(1))
Else
Pnr = Abs(Poly(0))
Qnr = Abs(Poly(1))
For s = 2 To nPoly - 1
Orient = LOrienta(Pnr, Qnr, Abs(Poly(s)))
If (Orient